<!--  -->
<template>
  <div>
    <el-button type="primary" @click="add" v-if="rows==null">保存</el-button>
    <el-button type="primary" @click="upd" v-if="rows!=null&&rows.approve_status==1">修改</el-button>
    <!-- <el-button type="primary" @click="lct">流程图</el-button>
    <el-button type="primary" @click="imp">导入</el-button> -->
    <el-divider></el-divider>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-header style="font-size: 20px;position: relative;left: -20px">
        基本信息
      </el-header>
      <div class="base">
          <div style="padding: 10px" class="grid-content bg-purple">
            <span>日期:
              <el-date-picker
                v-model="formInline.date"
                type="date"
                placeholder="选择日期" readonly="" style="width:150px">
              </el-date-picker>
            </span>
          </div>
          <div style="padding: 10px" class="grid-content bg-purple">
            <span>方案编号:
              <el-input
                v-model="formInline.id" readonly=""
                style="width:150px">
              </el-input>
            </span>
          </div>
          <div style="padding: 10px" class="grid-content bg-purple">
            <span>项目名称:
              <el-input placeholder="请选择" style="width:150px" v-model="formInline.pname" @focus="getPid">
              </el-input>
            </span>
          </div>
          <div style="padding: 10px" class="grid-content bg-purple">
            <span>方案名称:
              <el-input placeholder="请选择" style="width:150px" v-model="formInline.planName">
              </el-input>
            </span>
          </div>
          <div style="padding: 10px" class="grid-content bg-purple">
            <span>填报人:
              <el-input placeholder="请选择" readonly v-model="formInline.fillUser" style="width:150px">
              </el-input>
            </span>
          </div>
          <div style="padding: 10px" class="grid-content bg-purple1">
            <span style="margin-left:40px">方案说明:
              <el-input placeholder="请输入" type="textarea" v-model="formInline.planComment" style="width:1000px" >
              </el-input>
            </span>
          </div>
          <div style="padding: 10px" class="grid-content bg-purple1">
            <span style="margin-left:40px">备注:
              <el-input placeholder="请输入" type="textarea" v-model="formInline.comment" style="width:1000px" >
              </el-input>
            </span>
          </div> <br><br>
            <multi-file-upload
                style="width: 90%;margin-top: 30px"
                title="附件"
                action="http://localhost/uploads"
                :headers="{token: this.$store.state.token}"
                :show-button="checkRoute"
                @uploadSuccess="handleUploadSuccess"
                :parent-file-list="attachIds"
        ></multi-file-upload>
      </div>
    </el-form>
    <el-dialog
            title="项目名称"
            :visible.sync="dialogVisible"
            width="70%">
        <project-type-big-data v-on:row="row" v-if="dialogVisible" ></project-type-big-data>
    </el-dialog>
  </div>
</template>

<script>
import ProjectTypeBigData from '../../common/projectInfo/ProjectInfoList'
import {DateUtil} from "../../../model/common/DateUtil";
import WorkOrgPlanModel from '../../../model/nyx/WorkOrgPlanModel'
import {AttachemenInfoService} from "../../../model/gs/AttachemenInfoService";
const attachemenInfoService = AttachemenInfoService.getInstance()
var wm=new WorkOrgPlanModel();
export default {
  data () {
    return {
      formInline:{
        fillUser:sessionStorage.getItem('realName'),
        date:DateUtil.today(),
        id:"",
        name:"",
        planComment:"",
        comment:"",
        planName:""
      },
      dialogVisible:false,
      rows:{},
      checkRoute:true,
      attachIds:[]
    };
  },

  components: {ProjectTypeBigData},

  computed: {},

  mounted(){
    this.rows=this.$route.params.row
    if(this.rows!=null&&this.rows!=""){
      this.getFormInline()
      this.getFileList()
    }else{
      this.getId();
    }
  },

  methods: {
    getId(){
      wm.getId().then(response=>{
        this.formInline.id=response.data.message
      })
    },
    handleUploadSuccess(ids){
      this.formInline.attachIds=ids
      console.log(this.formInline)
    },
    row(row){
        this.dialogVisible=false
        this.formInline.pname=row.projectName
        this.formInline.xmId=row.id
    },
    add(){
       wm.save(this.formInline).then(response=>{
        console.log(response)
        this.$router.push("/WorkOrgPlanList")
      })
    },
    tjsp(){

    },
    lct(){

    },
    imp(){

    },
    getPid(){
        this.dialogVisible=true
    },
    upd(){
      console.log(this.formInline)
      wm.update(this.formInline).then(response=>{
        console.log(response)
        this.$router.push("/WorkOrgPlanList")
      })
    },
     getFormInline(){
      this.formInline.pname=this.rows.project_name
      this.formInline.id=this.rows.id
      this.formInline.date=this.rows.date
      this.formInline.xmId=this.rows.xmId
      this.formInline.name=this.rows.name
      this.formInline.fillUser=this.rows.user_realname
      this.formInline.planName=this.rows.plan_name
      this.formInline.planComment=this.rows.plan_comment
      this.formInline.comment=this.rows.comment
    },
    getFileList() {
      if(this.rows.attach_ids!=undefined){
        attachemenInfoService.getById(this.rows.attach_ids).then(response => {
          if (response.data.code === 0) {
              response.data.data.forEach(item => {
                  this.attachIds.push({
                      fileName: item.fileName,
                      uploadPerson: this.rows.user_realname,
                      uploadDate: item.uploadDate,
                      filePath: item.filePath
                  })
              })
            }
        })
      }
   },
  }
}

</script>
<style scoped>
.base,.details{
    width: 100%;
    display: flex;
    flex-wrap: wrap;
}
.bg-purple {
    background: #FFFFFF;
    border: 1px solid  darkgray;
    width: 21%;
    height: 50px;
    margin-top: -1px;
    margin-left: -1px;
}
.base .bg-purple{
  text-align: right;
}
.bg-purple1 {
    background: #FFFFFF;
    border: 1px solid  darkgray;
    width: 89%;
    line-height: 50px;
    text-align: right;
    margin-top: -1px;
    margin-left: -1px;
}
</style>